package com.coinland.study.base;

import android.arch.lifecycle.Lifecycle;

import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposeConverter;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;

/**
 * 类描述:
 * 创建人:  shenZ
 * 创建时间: 2019/8/22
 * 联系方式: 252079249@qq.com
 * 修改时间: 2019/8/22
 */
public abstract class BaseMvpActivity<T extends BasePresenter> extends BaseActivity implements BaseView {


    protected T mPresenter;


    @Override
    protected void onDestroy() {
        if (mPresenter != null) {
            mPresenter.detachView();
        }
        super.onDestroy();
    }



    /**
     * 绑定生命周期 防止MVP内存泄漏
     *
     * @param <T>
     * @return
     */
    @Override
    public <T> AutoDisposeConverter<T> bindAutoDispose() {
        return AutoDispose.autoDisposable(AndroidLifecycleScopeProvider
                .from(this, Lifecycle.Event.ON_DESTROY));
    }

}
